import os
Import('env', 'TOP_DIR')
# TOP_DIR = "E:\Project\C\mini_net"

def path_join(qian, hou):
    res = list(qian + '/' + hou)
    for i in range(0, len(res)):
        if res[i] == '\\':
            if i != len(res) - 1 and res[i + 1] == '\\':
                i += 1
            res[i] = '/'
        # if i > 0 and res[i - 1] != '/':
        #     res.insert(i, '/')

    return ''.join(res)

TEST_INCLUDE = [
                    path_join(TOP_DIR, '/test/'),
                    path_join(TOP_DIR, '/src/plat/'),
                    path_join(TOP_DIR, '/third_party/npcap/Include/'),
                    path_join(TOP_DIR, '/third_party/npcap/Include/pcap/')
                ]
print(TEST_INCLUDE)
TEST_LIB_PATH = [
                    # path_join(TOP_DIR, 'third_party/npcap/lib'),
                    path_join(TOP_DIR, 'third_party/npcap/lib/x64'),
                    # path_join(TOP_DIR, 'third_party/npcap/lib/ARM64')
                ]
print(TEST_LIB_PATH)
TEST_LIBS = ['ws2_32']
# TEST_LIBS.append("mingw32")
for each in TEST_LIB_PATH:
    for root, dirs, files in os.walk(each):
        if files != None:
            for file in files:
                #print(" file = ", file)
                TEST_LIBS.append(file.split('.')[0])



test_source_dir = [path_join(TOP_DIR, '/test'), path_join(TOP_DIR, '/src/plat')]
test_source_files = ['./main.c', path_join(TOP_DIR, '/src/plat/sys_plat.c')]
# for each in test_source_dir:
#     test_source_files.extend(env.Glob(path_join(each, '*.c')))

print(test_source_files)


test = env.Program(CPPPATH = TEST_INCLUDE, source = test_source_files, LIBS = TEST_LIBS, LIBPATH = TEST_LIB_PATH)
env.InstallAs(TOP_DIR + '/build/test.exe', test)